﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Ctef.Web.Models;
using System.Text;

namespace Ctef.Web.Extensions
{
    public static class PledgeExtensions
    {
        public static bool IsValid(this PledgeViewModel model)
        {
            decimal amount;
            return !(model == null || model.Name.IsNullOrWhiteSpace() ||
                model.Email.IsNullOrWhiteSpace() || !decimal.TryParse(model.Amount, out amount));
        }

        public static string ComposeEmailSubject(this PledgeViewModel model)
        {
            if (model == null || model.Name.IsNullOrWhiteSpace())
            {
                return null;
            }

            return "[CTEF donation] new pledge from  " + model.Name.Trim();
        }

        public static string ComposeEmailBody(this PledgeViewModel model)
        {
            if (model == null)
            {
                return null;
            }

            var buffer = new StringBuilder();
            buffer.Append("Name: "); buffer.AppendLine(model.Name.TrimOrEmpty());
            buffer.Append("Email: "); buffer.AppendLine(model.Email.TrimOrEmpty());
            buffer.Append("Phone: "); buffer.AppendLine(model.Phone.TrimOrEmpty());
            buffer.Append("Company: "); buffer.AppendLine(model.Company.TrimOrEmpty());
            buffer.Append("Amount: "); buffer.AppendLine(model.Amount.TrimOrEmpty());
            buffer.Append("Program(s): "); buffer.AppendLine(model.Programs.TrimOrEmpty());

            return buffer.ToString();
        }
    }
}